package com.letfox.ad.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.letfox.ad.enums.MaterialEnums;
import com.letfox.ad.service.PlanUserService;
import com.letfox.ad.user.model.ADPlanUAccount;
import com.letfox.ad.user.model.PlanADAccountU;
import com.letfox.ad.user.service.ADPlanUAccountService;
import com.letfox.ad.user.service.PlanADAccountService;
import com.letfox.common.model.ResultResponse;

@Service
public class PlanUserServiceImpl implements PlanUserService {
	
	@Autowired
	private ADPlanUAccountService adPlanUAccountService;
	@Autowired
	private PlanADAccountService planADAccountService;
	
	@Override
	public ResultResponse selectUserADLiset(String accountId,String startCreateTime,String endCreateTime,String startTime,String endTime) throws Exception{
		ResultResponse resultResponse=new ResultResponse();
		//查询条件
		Map<String, String> map=new HashMap<String, String>();
		map.put("accountId", accountId);
		map.put("startCreateTime",startCreateTime==""?null:startCreateTime);
		map.put("endCreateTime", endCreateTime==""?null:endCreateTime);
		map.put("startTime", startTime==""?null:startTime);
		map.put("endTime", endTime==""?null:endTime);
		//查询账号关联广告信息
		 List<PlanADAccountU> list=planADAccountService.selectUserADLiset(map);
		resultResponse.setData(list);
		return resultResponse;
	}

	@Override
	public ResultResponse insertPlanAccount(String accountId,String planId) throws Exception {
		ResultResponse resultResponse=new ResultResponse();
		ADPlanUAccount adPlanUAccount=new ADPlanUAccount();
		//账户ID
		adPlanUAccount.setAccountId(accountId);
		//广告ID
		adPlanUAccount.setAdPlanId(planId);
		//是否有效数据
		adPlanUAccount.setDel(MaterialEnums.Date.YES.getValue());
		//创建时间啊
		adPlanUAccount.setCreateTime(new Date());
		//修改时间
		adPlanUAccount.setUpdateTime(new Date());
		//创建人
		adPlanUAccount.setCreateBy("system");
		//修改人
		adPlanUAccount.setUpdateBy("system");
		//写入数据库
		int i=adPlanUAccountService.insert(adPlanUAccount);
		if(i<0)
			throw new Exception("sql insert erro");
		resultResponse.setData(i);
		return resultResponse;
	}
}
